<template>
	<view class="page-container">
		<view class="enroll">
			
			<view class="headline-name">
				<view class="name">{{enroll.name}}</view>
				<view class="num">使用次数：{{enroll.spare}}次</view>
			</view>
			<view class="li">劵码：{{enroll.spare1}}</view>
			<view class="li">生效日期：{{enroll.receive_end}}</view>
			<view class="li">截止日期：{{enroll.use_end}}</view>
			<view class="cut"></view>
			<view class="info" v-if="enroll.userDetail!=null">
				<view class="headline">报名信息：</view>
				<view class="li flex message">
					<view class="name">姓名：{{enroll.userDetail.name}}</view>
					<view class="sex">性别：{{enroll.userDetail.sex}}</view>
				</view>
				<view class="li">电话：{{enroll.userDetail.phone}}</view>
				<view class="li">毕业院校：{{enroll.userDetail.school}}</view>
			</view>
			
			<view class="but" @click="use">立即使用</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		getCurrentInstance,
	} from 'vue'
	import {
		onLoad,
		onShow,
		onShareAppMessage,
		onShareTimeline
	} from '@dcloudio/uni-app'
	const {
		proxy
	} = getCurrentInstance();


	const enroll = ref({
		"id": 1, //编号
		code:"",
		"create_user_id": null, //用户编号
		"create_user_name": null,
		"create_time": "2024-03-22 09:33:50", //领取时间
		"spare": "0", //街道编号，以逗号分割
		"spare1": null,
		"spare2": null,
		"limit": 0, //每页条数
		"offset": 10,
		"name": "100元优惠券XXX", //名称
		"receive_end": "2024-03-31 00:00:00", //领取截止时间
		"use_end": "2024-05-31 00:00:00" //使用截止时间
	})
	
	function use(){
		const user =  uni.getStorageSync('USERDATA');
		proxy.$request({
			url: `${proxy.$api.useActivity}`,
			method: "POST",
			data:{
				user_id:user.id,
				activity_id:enroll.value.id
			}
		}).then(res => {
			var data = uni.getStorageSync('ENROLLDATA');
			data.spare = parseInt(data.spare, 10) + 1;
			uni.setStorageSync('ENROLLDATA', data);
			enroll.value = data;
		})
	}

	onLoad((e) => {
		
		enroll.value = uni.getStorageSync('ENROLLDATA');
	})

	onShow(() => {

	})
</script>

<style lang="less" scoped>
	.page-container {
		// background: #F9D85D;
		font-size: 28rpx;
		padding: 40rpx;
		.enroll{
			width: 100%;
			margin-left: auto;
			margin-right: auto;
			background: white;
			border-radius: 16rpx;
			// height: 400rpx;
			box-shadow: 0px 0px 8px 0px rgba(55, 123, 245, 0.08);
			padding: 20rpx;
			.headline-name{
				display: flex;
				align-items: center;
				margin-top: 20rpx;
				.name{
					font-size: 35rpx;
					color: red;
				}
				.num{
					margin-left: auto;
				}
			}
			.li{
				margin: 15rpx 0;
			}
			.cut{
				width: 100%;
				border-bottom: dashed 1rpx #bbb;
				margin-top: 30rpx;
				margin-bottom: 30rpx;
			}
			
			.info{
				
				.sex{
					margin-left: 100rpx;
				}
				.headline{
					font-size: 32rpx;
					
				}
			}
		}
		
		.but{
			// padding: 20rpx;
			height: 75rpx;
			background: #F9D85D;
			margin-left: auto;
			margin-right: auto;
			text-align: center;
			line-height: 75rpx;
			font-size: 35rpx;
			margin-top: 30rpx;
			margin-bottom: 30rpx;
			border-radius: 50rpx;
		}
	}
</style>
